<template>
  <robin-editor class="editor" @cancel="hideEditor" @save="saveEditor" v-model="textValue" :imageUploader="uploadImg"
    :muiltImage="true">
  </robin-editor>
</template>

<script>
  import {
    newShopstory
  } from '@/api/new_pet.js'
  export default {
    data() {
      return {
        textValue: '',
        Pet_id: 0
      }
    },
    onLoad(option) {
      this.Pet_id = option.id
      this.textValue = uni.getStorageSync('textValue')
      uni.removeStorageSync('textValue')
    },
    methods: {
      hideEditor(e) {
        // console.log(e)
        uni.navigateBack()
      },
      saveEditor(e) {
        newShopstory(e.html, this.Pet_id).then(res => {
          // console.log(res)
          uni.switchTab({
            url: '/pages/tabbar/index/index'
          })
          this.$util.Tips({
            title: '编辑成功!'
          });
        }).catch(err => {
          this.$util.Tips({
            title: err
          });
        })

      },
      uploadImg(img, callback) {
        this.$util.uploadImage('blade-resource/oss/endpoint/put-file', img, function(res) {
          const data = JSON.parse(res)
          // console.log(data.data.link)
          callback(data.data.link)
        });
      }
    }
  }
</script>

<style lang="scss">

</style>
